from pdbc_p.pdbc import db_queryone, db_operation


username=""
def reg():
    username=input("输入用户名：")
    passwd=input("输入密码：")
    realname=input("输入你的真实姓名：")
    phonenumber=input("输入手机号：")
    address=input("输入地址：")
    result=db_queryone("select passwd from user_info where username='%s'"%username)
    if result==None:
        db_operation("INSERT into user_info values ('%s','%s','%s','%s','%s')"%(username,passwd,realname,phonenumber,address))
        print("注册成功")
        from ui_p.ui import start_menu
        start_menu()
    else:
        print("账户已存在，请重新输入：")
        reg()
def login():
    global username
    username = input("输入用户名：")
    passwd = input("输入密码：")
    result = db_queryone("select passwd from user_info where username='%s'" % username)
    if result!=None and passwd==result[0]:
            print("登录成功")
            from ui_p.ui import user_menu
            user_menu()
    else:
        print("用户名或密码错误，请重新输入")
        login()

def admin_login():
    from ui_p.ui import admin_menu
    username = input("输入用户名：")
    passwd = input("输入密码：")
    result = db_queryone("select passwd from administor_info where username='%s'" % username)
    if result != None and passwd == result[0]:
        print("登录成功")
        admin_menu()
    else:
        print("用户名或密码错误，请重新输入")
        admin_login()
